package xmlschema;

import com.sun.org.apache.xerces.internal.dom.ElementNSImpl;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;

import java.util.ArrayList;

import java.util.Calendar;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "Person")

@XmlType(propOrder = {"peopleID", "name", "street", "city", "state", "zipCode","phone", "social", "email","personal"})
public class Person {
    private int peopleID;
    private String Name;
    private String Street;
    private String City;
    private String State;
    private String ZipCode;
    private String Phone;
    private String Social;
    private String Email;
    private Object Personal;
    @XmlAttribute(name = "personal/@Title")
    private String Title;
    @XmlAttribute(name = "personal/@Age")
    private String Age;
    @XmlAttribute(name = "personal/@Gender")
    private String Gender;
    private LocalDate Birth;

    /**
     * @return the peopleID
     */


    public int getPeopleID() {
        return peopleID;
    }

    /**
     * @param peopleID the peopleID to set
     */
    public void setPeopleID(int peopleID) {
        this.peopleID = peopleID;
    }

    /**
     * @return the Name
     */
    public String getName() {
        return Name;
    }

    /**
     * @param Name the Name to set
     */
    public void setName(String Name) {
        this.Name = Name;
    }

    /**
     * @return the Street
     */
    public String getStreet() {
        return Street;
    }

    /**
     * @param Street the Street to set
     */
    public void setStreet(String Street) {
        this.Street = Street;
    }

    /**
     * @return the City
     */
    public String getCity() {
        return City;
    }

    /**
     * @param City the City to set
     */
    public void setCity(String City) {
        this.City = City;
    }

    /**
     * @return the State
     */
    public String getState() {
        return State;
    }

    /**
     * @param State the State to set
     */
    public void setState(String State) {
        this.State = State;
    }

    /**
     * @return the ZipCode
     */
    public String getZipCode() {
        return ZipCode;
    }

    /**
     * @param ZipCode the ZipCode to set
     */
    public void setZipCode(String ZipCode) {
        this.ZipCode = ZipCode;
    }

    /**
     * @return the Phone
     */
    public String getPhone() {
        return Phone;
    }

    /**
     * @param Phone the Phone to set
     */
    public void setPhone(String Phone) {
        this.Phone = Phone;
    }

    /**
     * @return the Social
     */
    public String getSocial() {
        return Social;
    }

    /**
     * @param Social the Social to set
     */
    public void setSocial(String Social) {
        this.Social = Social;
    }

    /**
     * @return the Email
     */
    public String getEmail() {
        return Email;
    }

    /**
     * @param Email the Email to set
     */
    public void setEmail(String Email) {
        this.Email = Email;
    }
    
    /**
     * @return the Personal
     */
    public Object getPersonal() {
        return Personal;
    }

    /**
     * @param Personal the Personal to set
     */
    public void setPersonal(Object Personal) {
        String Dy ="";
        String Mon="";
        String Yr = "";
        this.Personal = Personal;
        this.Title = ((ElementNSImpl)Personal).getAttributeNode("Title").getValue();
        this.Age = ((ElementNSImpl)Personal).getAttributeNode("Age").getValue();
        this.Gender = ((ElementNSImpl)Personal).getAttributeNode("Gender").getValue();
        Dy = ((ElementNSImpl)Personal).getAttributeNode("Day").getValue();
        Mon = ((ElementNSImpl)Personal).getAttributeNode("Month").getValue();
        Yr = ((ElementNSImpl)Personal).getAttributeNode("Year").getValue(); 
        this.Birth = LocalDate.of(Integer.parseInt(Yr), convertMonth(Mon), Integer.parseInt(Dy));
    }
    
    /**
     * @return the Title
     */
    public String getTitle() {
        return Title;
    }
    
    /**
     * @return the Gender
     */
    public String getGender() {
        return Gender;
    }
    
    /**
     * @return the Birth
     */
    public String getBirthDay() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
        return Birth.format(formatter);
    }
    
    public int GetAge(){
        LocalDate current = LocalDate.now();
        Period period = Birth.until(current);
        return period.getYears();
    }

    private int convertMonth(String Mon){
        int retVal=0;
        switch(Mon.toUpperCase()) {
         case "JAN":
            retVal = 1;
            break;
        case "FEB":
           retVal = 2;
           break;
        case "MAR":
           retVal = 3;
           break;
        case "APR":
           retVal = 4;
           break;
        case "MAY":
           retVal = 5;
           break;
        case "JUN":
           retVal = 6;
           break;
        case "JUL":
           retVal = 7;
           break;
        case "AUG":
           retVal = 8;
           break;
        case "SEP":
           retVal = 9;
           break;
        case "OCT":
           retVal = 10;
           break;
        case "NOV":
           retVal = 11;
           break;
        case "DEC":
           retVal = 12;
           break;
        }
        return retVal;
    }
}